const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: './src/js/index.js',
  output: {
    filename: '[name].js',
    path: resolve(__dirname, 'build'),
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      minify: {
        collapseWhitespace: true,
        removeComments: true
      }
    }),
  ],
  mode: 'development',
  // 解析模块的规则
  resolve: {
    // 配置解析模块路径别名：优点简写路径，缺点没有路径提示
    alias: {
      $css: resolve(__dirname, 'src/css')
    },
    // 配置省略路径的后缀名，默认是.js, .json
    // 注意，文件名不要取重名，否则会取js文件
    extensions: ['.js', '.json', '.css'],
    // 告诉webpack解析模块时是去找哪个目录， 默认是当前目录的node_module, 一直向外层找直到找到
    modules: [resolve(__dirname, '../../node_modules'), 'node_modules']
  }
}
